package com.dycx.food.converter;

import cn.hutool.core.bean.BeanUtil;
import com.dycx.food.dto.GoodsDTO;
import com.dycx.food.dto.OrderGoodsDTO;
import com.dycx.food.entity.GoodsDO;
import com.dycx.food.enums.OrderGoodsStatusEnum;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dycx.food.entity.OrderGoodsDO;
import com.dycx.food.vo.OrderGoodsVO;

/**
 * 商城订单商品详细(FoodOrderGoods)实体转换类
 *
 * @author wuzongbing
 * @since 2025-03-26 02:19:14
 */


@Data
public class OrderGoodsConverter implements Serializable {
    public static OrderGoodsDO dtoToEntity(OrderGoodsDTO dto) {
        if (dto == null) return null;
        OrderGoodsDO entity = BeanUtil.toBean(dto, OrderGoodsDO.class);
        return entity;
    }

    public static OrderGoodsVO entityToVo(OrderGoodsDO entity) {
        if (entity == null) return null;
        OrderGoodsVO vo = BeanUtil.toBean(entity, OrderGoodsVO.class);
        vo.setStatusName(OrderGoodsStatusEnum.converter(vo.getStatus()).getName());
        vo.setStatusStyle(OrderGoodsStatusEnum.converter(vo.getStatus()).getStyle());

        return vo;
    }

    public static List<OrderGoodsVO> entityToVoList(List<OrderGoodsDO> entityList) {
        List<OrderGoodsVO> voList = new ArrayList<>();
        for (OrderGoodsDO entity : entityList) {
            voList.add(entityToVo(entity));
        }
        return voList;
    }

    public static Page<OrderGoodsVO> entityToVoPage(Page<OrderGoodsDO> page) {

        List<OrderGoodsVO> newRecords = new ArrayList<>();

        List<OrderGoodsDO> records = page.getRecords();
        for (OrderGoodsDO entity : records) {
            newRecords.add(entityToVo(entity));
        }

        Page<OrderGoodsVO> voPage = new Page<>();
        voPage.setRecords(newRecords);
        voPage.setPages(page.getPages());
        voPage.setTotal(page.getTotal());
        voPage.setSize(page.getSize());
        voPage.setCurrent(page.getCurrent());

        return voPage;
    }

}
